# 41. 高效货运
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on('line', (line) => {
const values = line.split(' ').map(Number);
const [wa, wb, wt, pa, pb] = values;
const max = calc(wa, wb, wt, pa, pb);
console.log(max);
});
function calc(wa, wb, wt, pa, pb) {
let max = 0;
for(let a=1; a*wa<wt; a++) {
let last = wt - a*wa;
if (last%wb===0) {
let b = last/wb;
let profit = a*pa + b*pb;
max = Math.max(max, profit);
}
}
return max;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25